<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
$timezone = "Asia/Saigon";
if(function_exists('date_default_timezone_set'))
    date_default_timezone_set($timezone);
    
require_once '../../config/config.php';
require_once '../../plugin/Smarty/Smarty.class.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Util'          . DIRECTORY_SEPARATOR . 'SEO.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Util'          . DIRECTORY_SEPARATOR . 'Pager.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Util'          . DIRECTORY_SEPARATOR . 'Tool.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Context'       . DIRECTORY_SEPARATOR . 'BaseContext.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'ServiceResult' . DIRECTORY_SEPARATOR . 'ServiceResult.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'GameService.php';

$context = new BaseContext();
$result = new ServiceResult();
$gameService = new GameService();
if(isset($_POST) && !empty($_POST))
{
	if ($_POST["loaigame"] == 3)
	{
		$folder = 'offline';
	}
	else if($_POST["loaigame"] == 78)
	{
		$folder = 'kinhdien';
	}
	else if($_POST["loaigame"] == 2)
	{
		$folder = 'online';
	}
	else if($_POST["loaigame"] == 4)
	{
		$folder = 'webgame';
	}

	if($_POST["kieugame"])
	{
		$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
		$_POST['smallImage'] = 'games'.'/'. $folder .'/'. $kieugame.'/thumbnail'.'/'.$_POST['image'];
		$_POST['mediumImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
		$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
		$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/xlarge'.'/'.$_POST['xlargeImage'];
	}
	else
	{
		$_POST['smallImage'] = 'games'.'/'. $folder .'/'.'thumbnail'.'/'.$_POST['image'];
		$_POST['mediumImage'] = 'games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
		$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
		$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.'xlarge'.'/'.$_POST['xlargeImage'];
	}

	$value = $_POST['tag1'];
	$_POST['tag'] ='';
	$tagname ='';
	if ($value){
		foreach ($value as $v)
		{
			$tagname .= $v.',';
			$_POST['tag'] = substr($tagname,0,-1);
		}
	}
	$_POST['shortDetail'] = stripslashes($_POST['shortDetail']);
	$_POST['mediumDetail'] = stripslashes($_POST['mediumDetail']);
	$_POST['mediumName'] = stripslashes($_POST['mediumName']);
	$_POST['unique_name'] = SEO::friendly_url($_POST['mediumName']);
	$param = $_POST;
	$gameService ->deleteGameMMBGTempTPG($context, $result);	
	$gameService ->insertGameTemp($context, $result, $param);
	echo 1;
}else{
	echo 0;
}	
	
?>